import java.util.ArrayList;
import java.util.List;

public class num438 {
    public List<Integer> findAnagrams(String s, String p) {
        List<Integer> list = new ArrayList<>();
        int n =s.length(),m = p.length();
        int[] arr1 = new int[26];
        int[] arr2 = new int[26];
        for (int i = 0; i < m; i++) {
            arr1[p.charAt(i) - 'a'] ++;
        }
        int l = 0;
        for (int i = 0; i < n; i++) {
            arr2[s.charAt(i) - 'a'] ++;
            if(i - l + 1 > m) {
                arr2[s.charAt(l) - 'a'] --;
                l ++;
            }
            if(check(arr1,arr2)) {
                list.add(l);
            }
        }
        return list;
    }

    private boolean check(int[] arr1, int[] arr2) {
        for (int i = 0; i < 26; i++) {
            if(arr1[i] != arr2[i]) {
                return false;
            }
        }
        return true;
    }
}
